﻿@{
    ViewBag.Title = "导入用户";
}
<div class="container">
    <ol class="breadcrumb">
        <li><a href="/adm/usercenter">用户中心</a></li>
        <li><a href="/usercenter/userlist/@(ViewBag.HOSP_ID)">@(ViewBag.HOSPITAL_NAME) 职工列表</a></li>
        <li class="active">导入</li>
    </ol>
    <div class="panel panel-default">
        <div class="panel-body">
            @Html.MyLinkButton("btn_download", "下载模板文件")
            
            <small>系统默认导入sheet1（第一页）</small>
        </div>
    </div>
    <div id="panel01" class="panel panel-primary">
        <div class="panel-heading">第一步：上传导入文件</div>
        <div class="panel-body">
            <input type="file" name="uploadify" id="uploadify" />

        </div>
    </div>
    <div id="panel02" class="panel panel-default">
        <div class="panel-heading">第二步：验证并导入</div>
        <div class="panel-body">
            <button type="button" id="btn_ckimp" class="btn btn-default disabled">开始验证导入</button>
        </div>
    </div>
    <div id="panel03" class="panel panel-danger hidden">
        <div class="panel-heading">未通过验证，消息如下:</div>
        <div class="panel-body">
            <ul class="list-group" id="fail_content">
            </ul>
        </div>
    </div>
</div>
@section css
{
    <link href="@Url.Content("~/Content/uploadify/uploadify.css")" rel="stylesheet" />
}

@section script
{
    <script type="text/javascript" src="@Url.Content("~/Content/uploadify/jquery.uploadify.min.js")"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            var fileobj = { hospitalid: '@(ViewBag.HOSP_ID)' };

            function swichPanel(panelid) {
                var arr_panel = ["panel01", "panel02"];
                var panel_index = 0;
                for (var i in arr_panel) {
                    if (panelid == arr_panel[i]) {
                        panel_index = i;
                        $("#" + arr_panel[i]).addClass("panel-primary").removeClass("panel-default");
                    } else {
                        $("#" + arr_panel[i]).removeClass("panel-primary").addClass("panel-default");
                    }
                }

                if (panel_index == 1) {
                    $("#panel02").find("button").removeClass("disabled");
                    $('#uploadify').uploadify('destroy');
                    $('#uploadify').before("<label class='label label-success disabled'>上传成功</label>").remove();
                }
            }

            $("#btn_ckimp").click(function (parameters) {
                $.post("/usercenter/CheckImportUserFile", fileobj, function (data) {
                    if (data.flag) {
                        $("#panel02 .panel-body").find("button").addClass("disabled").text("导入成功！").after("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"/usercenter/userlist/@(ViewBag.HOSP_ID)\">查看导入结果</a>");
                    } else {
                        $("#panel03").removeClass("hidden");
                        $("#fail_content").empty().append(data.msg);
                    }
                });
            });

            function init(parameters) {
                var defaults = {
                    swf: '@Url.Content("~/Content/uploadify/uploadify.swf")',
                    uploader: '@Url.Content("~/Resource/UploadHandle_Import.ashx")',
                    cancelImg: '@Url.Content("~/Content/uploadify/uploadify-cancel.png")',
                    width: 200,
                    height: 30,
                    formData: { folder: 'importfiles', uploader: '@ViewBag.UserID' },
                    queueID: 'fileQueue',
                    buttonText: '选择文件',
                    fileTypeDesc: 'EXCEL 文件',
                    fileTypeExts: '*.xlsx; *.xls;',
                    auto: true,
                    multi: false,
                    onUploadSuccess: function (file, data, response) {
                        fileobj.filename = "importfiles/" + file.name;
                        if (data == "1") {
                            fileobj.flag = true;
                            swichPanel("panel02");
                            mainfn.msg("文件上传成功");
                        } else {
                            fileobj.flag = false;
                            mainfn.msg("文件上传失败");
                        }
                    }
                };

                $("#uploadify").uploadify(defaults);
            }

            $("#btn_download").click(function () {
                window.open("http://nj.baidupcs.com/file/e053cdb37274b370a0d6db188506a431?fid=4195030213-250528-736684460138271&time=1401260552&sign=FDTAXER-DCb740ccc5511e5e8fedcff06b081203-%2BC3E7JFje2LoXh5JVT1CludXD4U%3D&to=nb&fm=N,B,T,t&newver=1&expires=1401261152&rt=sh&r=747785501&logid=2742034255&sh=1&vuk=4195030213&fn=%E7%94%A8%E6%88%B7%E6%A8%A1%E6%9D%BF.xlsx");
            });

            init();


        });
    </script>

}